package com.yh.csx.bsf.ods;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.AbstractMatcherFilter;
import ch.qos.logback.core.spi.FilterReply;

import com.yh.csx.bsf.core.util.ContextUtils;
import com.yh.csx.bsf.core.util.StringUtils;

import com.yh.csx.bsf.health.base.EnumWarnType;
import com.yh.csx.bsf.health.base.Message;
import com.yh.csx.bsf.health.warn.WarnProvider;
import lombok.var;


/***
 * 为日志报警服务
 */
public class LogFilter extends AbstractMatcherFilter<ILoggingEvent> {
    @Override
    public FilterReply decide(ILoggingEvent event) {
        if(event.getLevel() == Level.ERROR) {
            var dingding =  ContextUtils.getBean(WarnProvider.class,false);
            Message message = new Message();
            message.setTitle("canal ods 仓库同步程序异常:"+ StringUtils.subString2(event.getFormattedMessage(),10));
            message.setContent(event.getFormattedMessage());
            message.setWarnType(EnumWarnType.WARN);
            dingding.notify();
            event.getFormattedMessage();
        }
        return FilterReply.NEUTRAL;
    }



}

